package com.jubaozan.framework.sentinel.stat;

import com.jubaozan.framework.sentinel.stat.traffic.TrafficLogSaver;
import com.jubaozan.framework.sentinel.stat.traffic.TrafficInterceptor;
import com.jubaozan.framework.sentinel.stat.traffic.config.TrafficStatConfig;
import com.jubaozan.framework.sentinel.stat.traffic.config.TrafficWebMvcConfigurer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author jiangjinwu
 * @version 1.0
 * @since 2025/7/28 16:51
 */

@Slf4j
@EnableScheduling
@ConditionalOnClass({TrafficInterceptor.class})
@EnableConfigurationProperties({TrafficStatConfig.class})
@ComponentScan(basePackages = {"com.jubaozan.framework.sentinel.stat"})
public class StatAutoConfiguration implements WebMvcConfigurer {

    @Bean
    @ConditionalOnProperty(
        name = {"framework.sentinel.stat.traffic.enabled"}
    )
    public TrafficInterceptor trafficInterceptor() {
        return new TrafficInterceptor();
    }

    @Bean
    @ConditionalOnProperty(
        name = {"framework.sentinel.stat.traffic.enabled"}
    )
    public TrafficWebMvcConfigurer trafficWebMvcConfigurer() {
        return new TrafficWebMvcConfigurer();
    }


    @Bean
    @ConditionalOnProperty(
        name = {"framework.sentinel.stat.traffic.enabled"}
    )
    public TrafficLogSaver trafficLogSaver(){
        return new TrafficLogSaver();
    }
}
